package com.xiangxiao.rpan.data.model;

import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.xiangxiao.rpan.data.enums.MessageTypeEnum;
import com.xiangxiao.rpan.data.enums.StatusEnum;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;

import javax.validation.constraints.NotNull;
import java.util.Date;

/**
 * @auther xiangxiao
 * @email 573768011@qq.com
 * @data 2024/5/9 20:47
 */
@Getter
@Setter
public abstract class BaseAlarm {
  /**
   * 获取目标类型(1:文件, 2:文件夹)
   * */
  private Integer type;

  /**
   * 告警ID
   */
  private Integer id;

  /**
   * 状态:(0: 失败, 1: 成功
   * */
  @NotNull
  private StatusEnum status;

  private Integer alarmType;

  /**
   * 布控任务类型，决定该告警所属的业务逻辑
   * @return
   */
  @NotNull
  protected MessageTypeEnum messageType;

  /**
   * 告警时间
   */
  @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
  protected Date time;

  public Integer getType() {
    return type;
  }

  public MessageTypeEnum getMessageType() {
    return messageType;
  }

  public StatusEnum getStatus() { return status; }

  public void setStatus(Integer i) {
    this.status = intToStatus(i);
  }

  public Date getTime() {
    return time;
  }

  public Integer getId() {
    return id;
  }

  public StatusEnum intToStatus(Integer value) {
    switch (value) {
      case 0:
        return StatusEnum.FAILED;
      case 1:
        return StatusEnum.FINISHED;
    }
    return null;
  }
}
